package net.cyl.controller;


import net.cyl.controller.request.LinkGroupAddRequest;
import net.cyl.controller.request.LinkGroupUpdateRequest;
import net.cyl.emums.BizCodeEnum;
import net.cyl.model.LinkGroupDO;
import net.cyl.service.LinkGroupService;
import net.cyl.util.JsonData;
import net.cyl.vo.LinkGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 曹玉林
 * @since 2025-05-14
 */
@RestController
@RequestMapping("/api/group/v1")
public class LinkGroupController {
    @Autowired
    private LinkGroupService linkGroupService;
    //创建分组
    @PostMapping("/add")
    public JsonData add(@RequestBody LinkGroupAddRequest request){
        int result = linkGroupService.add(request);
        return result>0?JsonData.buildSuccess():JsonData.buildResult(BizCodeEnum.GROUP_ADD_FAIL);
    }

    //删除分组
    @PostMapping("/del/{group_id}")
    public JsonData delete(@PathVariable("group_id") Long group_id){
        int result = linkGroupService.delete(group_id);
        return result>0?JsonData.buildSuccess():JsonData.buildResult(BizCodeEnum.GROUP_DELETE_FAIL);
    }

    //根据id找详情

    @GetMapping("/detail/{group_id}")
    public JsonData detail(@PathVariable("group_id") Long group_id) {
           LinkGroupVO linkgroupVO = linkGroupService.detail(group_id);
           return JsonData.buildSuccess(linkgroupVO);
    }

    @GetMapping("/list")
    public JsonData findUserAllLinkGroup() {
        List<LinkGroupVO> list = linkGroupService.findUserAllLinkGroup();
        return JsonData.buildSuccess(list);
    }

    //更新分组
    @PostMapping("/update")
    public JsonData update(@RequestBody LinkGroupUpdateRequest request){
           int result = linkGroupService.updateByIdf(request);
           return result>0?JsonData.buildSuccess():JsonData.buildResult(BizCodeEnum.GROUP_UPDATE_FAIL);
    }
}

